# 员工管理普通实现
# 增加:需要token-->登录获取token
# 改删查:需要token,获取员工ID-->登录获取token
import requests
# 定义员工增删改类
from common.get_token import get_token
from config import id


class ThrmEmpApi(object):
    # 增加员工方法
    @staticmethod
    def add_emp(token,json_data):
        resp = requests.post("http://ihrm-test.itheima.net/api/sys/user",
                     headers = {"Authorization":token},
                     json = json_data)
        return resp
    # 修改员工方法
    @staticmethod
    def update_emp(token,emp_id,json_data):
        resp = requests.put("http://ihrm-test.itheima.net/api/sys/user/" + emp_id,
                     headers = {"Authorization":token},
                     json = json_data)
        return resp
    # 查询员工
    @staticmethod
    def search_emp(token,emp_id):
        resp = requests.put("http://ihrm-test.itheima.net/api/sys/user/" + emp_id,
                     headers = {"Authorization":token})
        return resp
    # 删除员工方法
    @staticmethod
    def del_emp(token,emp_id):
        resp = requests.delete("http://ihrm-test.itheima.net/api/sys/user/" + emp_id,
                     headers = {"Authorization":token})
        return resp
if __name__ == '__main__':
    # 创建token,只需要创建一次,后面的接口都可以用,因此不要封装到接口
    # 添加员工
    # 获取token
    token = get_token()
    add_data = {"username": "asdb", "mobile": "15178978521", "workNumber": "123412412412"}
    resp = ThrmEmpApi.add_emp(token,add_data)
    print("添加员工",resp.json())
    # 修改员工
    update_data = {"username":"易烊千玺"}
    resp1 = ThrmEmpApi.update_emp(token,id,update_data)
    print("修改员工",resp1.json())
    # 查询员工
    resp2 = ThrmEmpApi.search_emp(token,id)
    print("查询员工",resp2.json())
    # 删除员工
    resp3 = ThrmEmpApi.del_emp(token,id)
    print("删除员工",resp3.json())

